/*	
 * 注册 
 */

mui.init();
var mask = mui.createMask(); //遮罩层
var city_leaber = "86";
var cityPicker3 = null;
var phone_type = "domestic";


//自定义弹窗

function toolTop(obj){
	var title = obj.title, content = obj.content, Tips = obj.Tips;
	if(title!='' || title!='undefined'){
		$('#toolTitle').text(title)
	}
	if(content != '' || content!='undefined'){
		$('#toolText').text(content)
	}
	if(!Tips){    // 默认false
		$('.toolTip-button').hide();
		$('.toolTip-conent').height(130)
	}else{
		$('.toolTip-button').show();
		$('.toolTip-conent').height('auto')
	}
	$('#toolTipbox').show();
	$('#CloseToolTip').click(function(){
		$('#toolTipbox').hide();
	});
}

//地区
/*三级联动*/
(function($, doc) {
	$.init();
	$.ready(function() {
		/**
		 * 获取对象属性的值
		 * 主要用于过滤三级联动中，可能出现的最低级的数据不存在的情况，实际开发中需要注意这一点；
		 * @param {Object} obj 对象
		 * @param {String} param 属性名
		 */
		var _getParam = function(obj, param) {
			return obj[param] || '';
		};
		if(city_leaber == "86" || city_leaber == "00886") {
			cityPicker3 = new $.PopPicker({
				layer: 3
			});
			cityPicker3.setData(cityData3);
			var showCityPickerButton = doc.getElementById('region');
			var cityResult3 = doc.getElementById('region');
			var provinceID = doc.getElementById('provinceid');
			var cityID = doc.getElementById('cityid');
			var areaID = doc.getElementById('areaid');
			showCityPickerButton.addEventListener('tap', function(event) {
				cityPicker3.show(function(items) {
					cityResult3.innerText = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
					provinceID.value = _getParam(items[0],'value');
					cityID.value = _getParam(items[1],'value');
					areaID.value = _getParam(items[2],'value');
					//返回 false 可以阻止选择框的关闭
					//return false;
				});
			}, false);
		}
	});
})(mui, document);

//注册发送验证码
$(document).on('tap', '#btn', function() {
	var phone = $("#quick_register_phone2").val(); //获取注册手机号
	var smscode = $("#quick_register_code2").val(); //验证码
	if(!phone) {
		toolTop({title:'温馨提示',content:'手机号码不能为空',Tips:false});
		return false;
	}
	var url = "/api/register/checkCode";
	mui.ajax(url,{
		data:{mobile:phone,type:1},
		dataType:"json",
		type:"post",
		success:function (data) {
			if(data.code == 10000){
				toolTop({title:'温馨提示',content:'发送成功',Tips:false});
				return false;
			}else{
				toolTop({title:'温馨提示',content:data.msg,Tips:false});
				return false;
			}
		},
		error:function (xhr,type,errorThrown) {
			console.log(type);
		}
	});
})





//注册
$(document).on("tap", "#enterprise", function() {
	var phone = $("#quick_register_phone2").val(); //获取手机号码
	var mobile = $("#quick_register_phone2").val(); //获取手机号码
	var pwVal = $('#quick_register_pw').val();    //登录密码
	var pwVal2 = $('#quick_register_pw2').val();    //确认密码
	var region_text_code = $("#region").text(); //地区
//	var phone_code = region_text_code.split("+")[1]; //截取
//	var phone_sure_code = phone_code.split(")")[0]; //截取
	
	var phone_verification_code = $("#quick_register_code2").val(); //获取手机验证码
	var region = $("#region").text(); //地区
	
	if(phone=='') {
		toolTop({title:'温馨提示',content:'请输入手机号码',Tips:false})
		return false;
	}
	if(phone_verification_code=='') {
		toolTop({title:'温馨提示',content:'请获取手机验证码',Tips:false})
		return false;
	}
	if(pwVal=='') {
		toolTop({title:'温馨提示',content:'请输入登录密码',Tips:false})
		return false;
	}
	if(pwVal2=='') {
		toolTop({title:'温馨提示',content:'请输入确认密码',Tips:false})
		return false;
	}
	if(region_text_code=='') {
		toolTop({title:'温馨提示',content:'请选择地区',Tips:false})
		return false;
	}
	
	if(phone!='' && phone_verification_code!='' && pwVal!='' && region_text_code!=''){
		toolTop({title:'注册成功',content:'恭喜您，注册成功',Tips:true})
	}
	$.ajax({
		url:"/api/register/register",
		data:$("#regForm").serialize(),
		dataType:"json",
		type:"post",
		success:function (data) {
			if(data.code == 10000){
				toolTop({title:'注册成功',content:'恭喜您，注册成功',Tips:true});
			}else{
				toolTop({title:'温馨提示',content:data.msg,Tips:false});
			}
		}
	});
	
})
//点击跟换地区
$(document).on('tap', '.region_text', function() {
	var region_text = $(this).text(); //地区值
	var region_text_Country = region_text.split("(")[0];
	$("#region_text_Country").text(region_text_Country);
	var region_text_code = region_text.split("(")[1];
	$("#region_text_code").text("(" + region_text_code);
	var city_leabers = $(this).children("a").attr('leaber_num');
	if(city_leabers == "86") {
		phone_type = "domestic";
	} else {
		phone_type = "international";
	}
	/*三级联动*/
	(function($, doc) {
		$.init();
		$.ready(function() {
			/**
			 * 获取对象属性的值
			 * 主要用于过滤三级联动中，可能出现的最低级的数据不存在的情况，实际开发中需要注意这一点；
			 * @param {Object} obj 对象
			 * @param {String} param 属性名
			 */
			var _getParam = function(obj, param) {
				return obj[param] || '';
			};

			if(city_leabers == "86") {
				cityPicker3 = new $.PopPicker({
					layer: 3
				});
				cityPicker3.setData(cityData3);
				var showCityPickerButton = doc.getElementById('region');
				var cityResult3 = doc.getElementById('region');
				var provinceID = doc.getElementById('provinceid');
				var cityID = doc.getElementById('cityid');
				var areaID = doc.getElementById('areaid');
				showCityPickerButton.addEventListener('tap', function(event) {
					cityPicker3.show(function(items) {
						cityResult3.innerText = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
						provinceID.value = _getParam(items[0],'value');
						cityID.value = _getParam(items[1],'value');
						areaID.value = _getParam(items[2],'value');
						//返回 false 可以阻止选择框的关闭
						//return false;
					});
				}, false);
			} else if(city_leabers == "00886") {
				cityPicker3 = new $.PopPicker({
					layer: 3
				});
				cityPicker3.setData(cityData5);
				var showCityPickerButton = doc.getElementById('region');
				var cityResult3 = doc.getElementById('region');
				showCityPickerButton.addEventListener('tap', function(event) {
					cityPicker3.show(function(items) {
						cityResult3.innerText = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
						//返回 false 可以阻止选择框的关闭
						//return false;
					});
				}, false);
			} else if(city_leabers == "60") {
				cityPicker3 = new $.PopPicker({
					layer: 3
				});
				cityPicker3.setData(cityData4);
				var showCityPickerButton = doc.getElementById('region');
				var cityResult3 = doc.getElementById('region');
				showCityPickerButton.addEventListener('tap', function(event) {
					cityPicker3.show(function(items) {
						cityResult3.innerText = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
						//返回 false 可以阻止选择框的关闭
						//return false;
					});
				}, false);
			} else if(city_leabers == "00852") {

				cityPicker3 = new $.PopPicker({
					layer: 3
				});
				cityPicker3.setData(cityData6);
				var showCityPickerButton = doc.getElementById('region');
				var cityResult3 = doc.getElementById('region');
				showCityPickerButton.addEventListener('tap', function(event) {
					cityPicker3.show(function(items) {
						cityResult3.innerText = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
						//返回 false 可以阻止选择框的关闭
						//return false;
					});
				}, false);

			} else {

				cityPicker3 = new $.PopPicker({
					layer: 3
				});
				cityPicker3.setData(cityData7);
				var showCityPickerButton = doc.getElementById('region');
				var cityResult3 = doc.getElementById('region');
				showCityPickerButton.addEventListener('tap', function(event) {
					cityPicker3.show(function(items) {
						cityResult3.innerText = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
						//返回 false 可以阻止选择框的关闭
						//return false;
					});
				}, false);

			}

		});
	})(mui, document);
})

$(document).on('tap', '.return', function() {
//	window.top.location.href = "login.html"
	window.top.history.go(-1);
})
